package com.singzi.leetcode.N900;

import java.util.HashMap;

public class T0819 {
    public static void main(String[] args) {
        Solution08196 solution08196 = new Solution08196();
        System.out.println(solution08196.mostCommonWord("Bob hit a ball, the hit BALL flew far after it was hit.", new String[]{"hit"}));
    }

}
class Solution08196 {
    public String mostCommonWord(String paragraph, String[] banned) {
        //so easy

        HashMap<String, Integer> map = new HashMap<>();
        int index = 0;
        for(int i = 0;i <= paragraph.length();i++){
            if(i == paragraph.length() || paragraph.charAt(i) == ' '){
                String str = paragraph.substring(index, i);
                map.put(str, map.getOrDefault(str,1)+1);
                index = i;
            }

        }
        for(String ban:banned){
            map.remove(ban);
        }
        int max = 0;
        StringBuilder ans = new StringBuilder();
        for(String key:map.keySet()){
            if(map.get(key) > max){
                max = map.get(key);
                ans = new StringBuilder(key);
            }
        }
        return ans.toString();

    }
}
